package com.qdsg.modulesihealsdk.ui;

import android.graphics.RectF;
import android.media.FaceDetector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by 56228 on 2019-01-02.
 */

public class FaceImage {
    private static final float MIN_FACE_AREA = 12500f;

    private byte[] faceBmpArray;

    private boolean hasFaces;
    private int faceNum;
    private List<FaceDetector.Face> faceList;
    private List<RectF> faceRectList;
    private long timestamp;

    public FaceImage(int faceNum, FaceDetector.Face[] faces, byte[] faceBmpArray, long timestamp) {
        this.faceNum = faceNum;
        this.faceList = Arrays.asList(faces);
        this.faceBmpArray = faceBmpArray;
        this.timestamp = timestamp;

        if (faceNum > 0 && faceList != null && faceList.size() > 0) {
            hasFaces = true;
            faceRectList = new ArrayList<>(faceNum);
        }
    }

    public boolean hasValidFace() {
        if (isHasFaces() && faceRectList != null && faceRectList.size() > 0) {
            for (RectF faceRect : faceRectList) {
                float area = faceRect.width() * faceRect.height();
                if (area >= MIN_FACE_AREA) {
                    return true;
                }
            }
        }
        return false;
    }

    public byte[] getFaceBmpArray() {
        return faceBmpArray;
    }

    public void setFaceBmpArray(byte[] faceBmpArray) {
        this.faceBmpArray = faceBmpArray;
    }

    public boolean isHasFaces() {
        return hasFaces;
    }

    public void setHasFaces(boolean hasFaces) {
        this.hasFaces = hasFaces;
    }

    public int getFaceNum() {
        return faceNum;
    }

    public void setFaceNum(int faceNum) {
        this.faceNum = faceNum;
    }

    public List<FaceDetector.Face> getFaceList() {
        return faceList;
    }

    public void setFaceList(List<FaceDetector.Face> faceList) {
        this.faceList = faceList;
    }

    public List<RectF> getFaceRectList() {
        return faceRectList;
    }

    public void setFaceRectList(List<RectF> faceRectList) {
        this.faceRectList = faceRectList;
    }

    public void setFaceRect(int faceIndex, RectF faceRect) {
        faceRectList.add(faceIndex, faceRect);
    }
}
